package com.tang.controller;

import com.github.pagehelper.PageInfo;
import com.tang.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author Tom
 * @ClassName DeleteController
 * @Date 2021/10/29 22:25
 */
 @Controller
 @RequestMapping("/delete")
public class DeleteController {
  @Autowired
  private BookService bookService;
  //删除书籍后,重定向到首页
  @RequestMapping("/deleteBook/{bookId}")
  public String deleteBook(@PathVariable("bookId") int id, HttpServletRequest request){
   bookService.deleteBookById(id);
      HttpSession session = request.getSession();
      PageInfo page = (PageInfo) session.getAttribute("page");
      int currentPage = page.getPageNum();
   return "redirect:/admin/queryAll?currentPage="+currentPage;
  }
}
    